<template>
  <footer>
    <van-tabbar route v-model="active" active-color="#3296fa" inactive-color="#666">
      <van-tabbar-item :to="obj" :name="obj.name" v-for="(obj,index) in allData" :key="index">
        <van-icon size="18" class="iconfont" class-prefix="icon" :name="obj.iconName" slot="icon"/>
        <span class="fontText">{{obj.text}}</span>
      </van-tabbar-item>
    </van-tabbar>
  </footer>
</template>

<script>
import { mapState } from 'vuex';
export default {
  data() {
    return {
      active: 'home',
      allData: [
        {
          iconName: 'shouye',
          text: '首页',
          to: '/layout/home',
          name: 'home'
        },
        {
          iconName: 'wenda',
          text: '问答',
          to: '/layout/ask',
          name: 'ask'
        },
        {
          iconName: 'shipin',
          text: '视频',
          to: '/layout/video',
          name: 'video'
        },
        {
          iconName: 'wode',
          text: this.token ? '我的' : '未登录',
          to: '/layout/user',
          name: 'user'
        }
      ]
    };
  },
  computed: {
    ...mapState(['token'])
  },
  watch:{
    token: {
      handler(newVal) {
        this.allData[3].text = newVal.token ? '我的' : '未登录' 
      }, 
      deep: true,
      immediate:true
    }
  }
}
</script>

<style scoped lang="less">
  .fontText {
    size: 20px;
  }
</style>